package com.mingzhi.lotterysystem.dao.mapper;

import com.mingzhi.lotterysystem.dao.dataobject.ActivityDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityMapper {

    @Insert("insert into activity (activity_name,description,status)" +
            " values (#{activityName},#{description},#{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer insert(ActivityDO activityDO);

    /**
     * 查询活动个数
     *
     * @return
     */
    @Select("select count(1) from activity")
    Integer count();

    /**
     * 查询活动列表
     *
     * @param offset
     * @param pageSize
     * @return
     */
    @Select("select * from activity order by id desc limit #{offset},#{pageSize}")
    List<ActivityDO> selectActivityList(@Param("offset") Integer offset,
                                        @Param("pageSize") Integer pageSize);

    @Select("select * from activity where id = #{activityId}")
    ActivityDO selectActivityId(@Param("activityId") Long activityId);

    @Update("update activity set status = #{status} where id = #{activityId}")
    void updateStatus(@Param("activityId") Long activityId,
                      @Param("status") String status);

}
